package com.rgbgame.game;

import com.rgbgame.util.Util;

/**
 * A com.rgbgame.game.Pose object consists of:
 * a set of Particles
 * @author Will
 * @date Mar 4, 2008 - 1:50:46 PM
 */
public class Pose {
    private Vector3d rawPosition[];
    public float targetSpring[];

    private int numParticles;

    public Pose(Vector3d _rawPosition[]) {
        rawPosition = new Vector3d[_rawPosition.length];
        for (int i = 0; i < _rawPosition.length; i++) {
            rawPosition[i] = new Vector3d(_rawPosition[i]);
        }
        numParticles = rawPosition.length;
        targetSpring = new float[(numParticles * (numParticles - 1) / 2)];
        getSpringLengths();
    }

    public Pose(Particle[] _p) {
        this(Util.particlesToVectors(_p));
    }

    private void getSpringLengths() {
        for (int i = 0; i < numParticles - 1; i++) {
            for (int j = i + 1; j < numParticles; j++) {
                targetSpring[getSpringIndex(i, j)] = rawPosition[i]
                        .distanceTo(rawPosition[j]);
            }
        }
    }

    private int getSpringIndex(int _i, int _j) {
        int result = 0;
        for (int i = 0; i < _i; i++) {
            result += numParticles - 2 - i;
        }
        result += _j - 1;
        return result;
    }
}
